<?php

namespace app\admin\controller;

use think\Request;
use think\Db;
use app\admin\model\System as mSystem;

class System extends Base
{
    protected $beforeActionList = [
        'get_config' => ['only'=>'index'],
    ];

    protected function get_config()
    {
        $data = Db::name('system')->select();
        foreach ($data as $k=>$v){
           $this->assign($v['en_name'],json_decode($v['config'],true));
        }
    }

    public function index()
    {
        return view();
    }

    public function store(Request $request)
    {
        $data['zh_name'] = $request->post('zh_name');
        $data['en_name'] = $request->post('en_name');

        $data['config'] = $request->except(['zh_name','en_name'],'post');


        if ($request->has('keywords')){
            $data['config']['keywords'] = str_replace('，',',',$data['config']['keywords']);
        }

        $data['config'] = json_encode($data['config']);

        return mSystem::mStore($data);
    }
}
